<?php
$tmpRing = RingtonePeer::getRingtoneById($ringtone->getId());
?>
<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container" style="overflow: auto;">
<fieldset id="sf_fieldset_none" class="">

<form id="sf_admin_edit_form" action="<?php echo url_for('ringtone/saveRtModerate') ?>" enctype="multipart/form-data" method="post" name="sf_admin_edit_form">
<input id="id" type="hidden" value="<?php echo $ringtone->getId()?>" name="id"/>

<div style="height: 120px;margin-bottom:10px; border-bottom: 1px solid #D5DDF3;">

	<div class="form-row" style="width: 120px; float:left;"> 
	  <div class="content<?php if ($sf_request->hasError('ringtone{avatar_path}')): ?> form-error<?php endif; ?>">
	  <?php if ($sf_request->hasError('ringtone{avatar_path}')): ?>
	    <?php echo form_error('ringtone{avatar_path}', array('class' => 'form-error-msg')) ?>
	    
	  <?php endif; ?>
	
		<div class="avatar">
	  	<?php if (null == $ringtone->getAvatarPath()): 
	  		echo '<img style="width:100px;height:100px;" src="' . image_path('default_avatar.gif') . '" alt="" />';
	  		else:
	  		echo '<img style="width:100px;height:100px;" src="' . $ringtone->getFullAvatarPath() . '" alt="" />';
	  		endif;
	  		?>
	  	</div>
	    </div>
	</div>
	
	<div style="padding-top: 5px;width: 500px; float:left;">
		<label>Nhạc chuông</label>
	    <div class="content">
	        <object width="290" height="24" id="audioplayer1" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
				<param value="player.swf" name="movie"/>
				<param value="playerID=1&amp;soundFile=<?php echo $ringtone->getFullFilePathMp3();?>" name="FlashVars"/>
				<param value="high" name="quality"/>
				<param value="false" name="menu"/>
				<param value="transparent" name="wmode"/>
			</object>
		<br/>
		<?php if ($firstVocal):?>
			<br/>
			<label>Vocal đầu tiên</label>
			<object width="290" height="24" id="audioplayer2" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
				<param value="player.swf" name="movie"/>
				<param value="playerID=1&amp;soundFile=http://media.sangtao.funring.vn/ringtone/vocals/<?php echo $firstVocal->getVocalPath();?>" name="FlashVars"/>
				<param value="high" name="quality"/>
				<param value="false" name="menu"/>
				<param value="transparent" name="wmode"/>
			</object>
		<?php endif; ?>
		<?php if ($tmpRing[0]['vocal_path']):?>
			<br/><br/>
			<label>Vocal ứng với nhạc chuông hiện tại</label>
			<object width="290" height="24" id="audioplayer3" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
				<param value="player.swf" name="movie"/>
				<param value="playerID=1&amp;soundFile=http://media.sangtao.funring.vn/ringtone/vocals/<?php echo $tmpRing[0]['vocal_path'];?>" name="FlashVars"/>
				<param value="high" name="quality"/>
				<param value="false" name="menu"/>
				<param value="transparent" name="wmode"/>
			</object>
		<?php endif; ?>	
	    </div>
	    <!-- <p><a href="<?php echo $origin_full_path; ?>" title="Download Ringtone">Download Nhạc Chuông</a></p> -->
	</div>
</div>

<div style="width: 600px">
    RT: <?php echo $tmpRing[0]['total_download'] ?>
    | RBT: <?php echo $tmpRing[0]['total_set'] ?>
    | Last:
    <?php
        if ($tmpRing[0]['imuzik_last_downloaded'] == NULL)
            echo 'NULL';
        else
            echo $tmpRing[0]['imuzik_last_downloaded'] ;
    ?>
    | Hidden:
    <?php
        if ($tmpRing[0]['imuzik_hidden_time'] == NULL)
            echo 'NULL';
        else
            echo $tmpRing[0]['imuzik_hidden_time'] ;
    ?>
</div>

<div id="relation-song">
<?php if(is_array($ringtone_related) && count($ringtone_related) > 0){	?>
	<span class="relation-title">
		Các bài nhạc cùng tên của tác giả:
		<a onclick="showall()" id="showall" style="cursor: pointer;">Show all</a>
	</span>
	<div class="showlist" id ="name1" style="display: none;">
	
	<table class="relation-tb" width="630px" cellpadding="0" cellspacing="0" border="1">
		<tr>
			<th>Bài hát</th>
			<th>RT</th>
			<th>RBT</th>
			<th>DEL</th>
			<th>Sáng tác</th>
		</tr>
		<?php 	foreach($ringtone_related as $item){ ?>
		<tr>
			<td width="260">
				<div class="player">
					<p><?php echo $item->getName()?></p>
					<object width="250" height="24" id="audioplayer1" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
					<param value="player.swf" name="movie"/>
					<param value="playerID=1&amp;soundFile=<?php echo $item->getFullFilePathMp3();?>" name="FlashVars"/>
					<param value="high" name="quality"/>
					<param value="false" name="menu"/>
					<param value="transparent" name="wmode"/>
					</object>
				</div>
			</td>
			<td width="15" align="center">
				<?php //echo $item->getRtStatus()?>
				<?php 
					switch ($item->getOrInitRingtoneStatus()->getRtApprove()){
						case '1':
							echo '1-D';
							break;
						case '2':
							echo '2-TC';
							break;
						case '3':
							echo '3-VMSCD';
							break;
						case '0':
						default:
							echo '0-VGCD';
							break;
					}
				?>
			</td>
			<td width="15" align="center"><?php echo $item->getOrInitRingtoneStatus()->getRbtApprove() //$item->getRbtStatus()?></td>
			<td width="15" align="center">
				<?php 
				switch ($item->getOrInitRingtoneStatus()->getRtDelete()){
						case '1':
							echo 'A';
							break;
						case '2':
							echo 'U';
							break;
						case '0':
						default:
							echo 'N';
							break;
				}
				?>
			</td>
			<td><?php echo $item->getComposerName()?></td>
		</tr>
		<?php }	?>
	</table>
	
	</div>
<?php } ?>

<!--  Tất cả các bài đã thành nhạc chuông cùng tên -->
<?php if(is_array($ringtone_related_all) && count($ringtone_related_all) > 0){	?>
	<br clear="all" />
	<span class="relation-title">Các bài nhạc chuông cùng tên:<a onclick="showall_all()" id="showall-all" style="cursor: pointer;">Show all</a></span>
	<div class="showlist" id ="name2" style="display: none;">
		<table class="relation-tb" width="630px" cellpadding="0" cellspacing="0" border="1">
		<tr>
			<th>Bài hát</th>
			<th>RT</th>
			<th>RBT</th>
			<th>DEL</th>
			<th>Sáng tác</th>
		</tr>
		<?php 	foreach($ringtone_related_all as $item){ ?>
		<tr>
			<td width="260">
				<div class="player">
					<p><?php echo $item->getName()?></p>
					<object width="250" height="24" id="audioplayer1" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
					<param value="player.swf" name="movie"/>
					<param value="playerID=1&amp;soundFile=<?php echo $item->getFullFilePathMp3();?>" name="FlashVars"/>
					<param value="high" name="quality"/>
					<param value="false" name="menu"/>
					<param value="transparent" name="wmode"/>
					</object>
				</div>
			</td>
			<td width="15" align="center">
				<?php 
					switch ($item->getOrInitRingtoneStatus()->getRtApprove()){
						case '1':
							echo '1-D';
							break;
						case '2':
							echo '2-TC';
							break;
						case '3':
							echo '3-VMSCD';
							break;
						case '0':
						default:
							echo '0-VGCD';
							break;
					}
				?>
			</td>
			<td width="15" align="center"><?php echo $item->getOrInitRingtoneStatus()->getRbtApprove();//echo $item->getRbtStatus()?></td>
			<td width="15" align="center">
				<?php 
					switch ($item->getOrInitRingtoneStatus()->getRtDelete()){
						case '1':
							echo 'A';
							break;
						case '2':
							echo 'U';
							break;
						case '0':
						default:
							echo 'N';
							break;
					}
				?>
			</td>
			<td><?php echo $item->getComposerName()?></td>
		</tr>
		<?php }	?>
	</table>
	</div>
<?php } ?>
</div>


<div class="form-row">
  <label class="required" for="ringtone_name">Tên Ringtone</label>
  <div class="content">
    <input type="text" size="50" value="<?php echo $ringtone->getName()?>" id="ringtone_name" name="ringtone[name]"/>
  	<a href="#" onclick="showrelation()">Bài liên quan</a>
  </div>
</div>

<div class="form-row">
  <label class="required" for="ringtone_name">Tên người tạo</label>
  <div class="content">
    <input type="text" size="50" readonly="readonly" value="<?php echo $ringtone->getCreatorName()?>" id="ringtone_create_name"/>  	
  </div>
</div>

<div class="form-row">
  <label class="required" for="ringtone_description">Mô tả</label>
  <div class="content">
    <textarea style="width: 295px;" id="ringtone_description" name="ringtone[description]" cols="55" rows="3"> <?php echo $ringtone->getRingtoneExtra()->getDescription(); ?></textarea>
  </div>
</div>



<div class="form-row">
  <label class="required" for="ringtone_category_id">Thể loại</label>
  <div class="content">
        <?php  echo select_tag('ringtone[category_id]', options_for_select($category_list, $ringtone->getCategoryId()), array('class' => 'full', 'peer_method' => 'getListCategory')); ?>
  </div>
</div>

<div class="form-row">
  <?php echo label_for('ringtone[composer_name]', 'Sáng tác', '') ?>
  <div class="content<?php if ($sf_request->hasError('ringtone{composer_name}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('ringtone{composer_name}')): ?>
    <?php echo form_error('ringtone{composer_name}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_tag($ringtone, 'getComposerName', array (
  'size' => 50,
  'control_name' => 'ringtone[composer_name]',
)); echo $value ? $value : '&nbsp;' ?>

	<?php if ($ringtone->getComposedByUser() == 1): 
	  			$cbu_checked = 'checked="checked"';
	  		else:
	  			$cbu_checked = '';
	  		endif;
	  ?>
    <input style="width: 20px" type="checkbox" name="ringtone[composed_by_user]" value="1" id="ringtone_composed_by_user" <?php echo $cbu_checked ?> onclick="javascript:updateComposerName();" />
    Tự sáng tác
    </div>
</div>

<!-- add by danhpt 2011-10-18 : show infor : valid_datetime, contract_index, contract_index_number -->
<div class="form-row">
  <label class="required" for="valid_datetime">Hạn hợp đồng</label>
  	<?php 
  		//$value1 = isset($startDate) ? $startDate : null;
        $value2 = (($ringtone_extra->getValidDatetime() != "") ? $ringtone_extra->getValidDatetime() : date('Y-m-d'));
        $options = array (
        	'rich' => true,                                                                  
            'calendar_button_img' => '/sf/sf_admin/images/date.png',
        );
        $options = _parse_attributes($options);
        //$before = _get_option($options, 'before', '');
        //$middle = _get_option($options, 'middle', '');
        $after  = _get_option($options, 'after', '');
  	?>
  	 <div class="content">
		<?php echo input_date_tag('valid_datetime', $value2, $options).$after; ?>
	 </div>	
</div>
<div class="form-row">
  <label class="required" for="contract_index">Phục lục</label>
  <div class="content">
    <input type="text" size="50" value="<?php echo$ringtone_extra->getContractIndex() ?>" id="contract_index" name="contract_index" />  	
  </div>
</div>
<div class="form-row">
  <label class="required" for="contract_index_number">STT trên phục lục</label>
  <div class="content">
    <input type="text" size="50" value="<?php echo$ringtone_extra->getContractIndexNumber() ?>" id="contract_index_number" name="contract_index_number"/>  	
  </div>
</div>
<!-- end by danhpt 2011-10-18 -->

<br/><div style="border-top: 1px solid #D5DDF3"></div>
<br/>

<!-- <div class="form-row">
  <?php echo label_for('ringtone[composed_by_user]', 'Tự sáng tác', '') ?>
  <div class="content<?php if ($sf_request->hasError('ringtone{composed_by_user}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('ringtone{composed_by_user}')): ?>
    <?php echo form_error('ringtone{composed_by_user}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>
  
  <?php if ($ringtone->getComposedByUser() == 1): 
  			$cbu_checked = 'checked="checked"';
  		else:
  			$cbu_checked = '';
  		endif;
  ?>

  <input type="checkbox" name="ringtone[composed_by_user]" value="1" id="ringtone_composed_by_user" <?php echo $cbu_checked ?> onclick="javascript:updateComposerName();" />
    </div>
</div> -->

<input type="hidden" name="creatorname" id ="creatorname" value="<?php echo $ringtone->getCreatorName()?>" />

<?php //include_partial('origin_player', array('ringtone' => $ringtone)); ?>

<div id="approve-row" class="form-row">
  	<label for="ringtone_approved" class="required">Chọn đồng bộ:</label>
  	<div class="content">
  		<?php if($ringtone_sys == null){	?>
  		<input type="checkbox" name="syschornize" id="syschornize" value="1" />
  		<?php } else {?>
  		<input type="checkbox" name="syschornize" id="syschornize" value="1" checked="checked" />
  		<?php } ?>
	</div>
</div>
<?php 
$approve_description = $rtstatus->getRtApproveDescription();
include_partial('approve_part', array('approve_description' => $approve_description, 'approve_status' => $ringtone->getOrInitRingtoneStatus()->getRtApprove(), 'list_reasons'=>$list_reasons)) 
?>
<?php
$delete_description = $rtstatus->getRtDeleteDescription(); 
include_partial('delete_part', array('delete_description' => $delete_description, 'delete_status' => $ringtone->getOrInitRingtoneStatus()->getRtDelete(), 'list_reasons'=>$list_reasons)) 
?>

<?php include_partial('popup_edit_actions', array('ringtone' => $ringtone, 'redirect' => true)) ?>

</form>
<ul class="sf_admin_actions">
</ul>
</fieldset>
</div>
<script>
showOrHideReasonRow(document.getElementById('approve-status-select'), 'reject_info', 2);
showOrHideReasonRow(document.getElementById('delete-status-select'), 'delete_info', 2);
// thang add
function showapp(el){
	if(el.value == '1'){
		document.getElementById('approve-status-select').value = 2;
		document.getElementById('approve-status-select').disabled="disabled";
		document.getElementById('approve_reason').disabled="disabled";
		showOrHideReasonRow(el, 'reject_info', 1);
		document.getElementById('approve_description').readonly="readonly";
		document.getElementById('approve_description').value = "Xóa bởi admin";
	}else{
		document.getElementById('approve-status-select').value = '0';
		document.getElementById('approve-status-select').disabled = false;
		document.getElementById('approve_reason').disabled = false;
		showOrHideReasonRow(el, 'reject_info', 999);
		document.getElementById('approve_description').value = "...nhập thông tin mô tả ở đây";
	}
}

function showrelation(){
	
    //new Ajax.Updater('relation-song',
     //       '/ringtone/releation?name='+value,
    //        {asynchronous:true, evalScripts: true}
    // );
    
    var val = document.getElementById('ringtone_name').value;
    var ringid  = '<?php echo $ringid ?>';
	$.ajax({
		  url: '/ringtone/relation?name='+val+'&ringid='+ringid,
		  success: function(data) {
		    $('#relation-song').html(data);
		  }
		});
}

function showall(){
	if(document.getElementById('name1').style.display=="none"){
		document.getElementById('name1').style.display="block";
		document.getElementById('showall').innerHTML = "Hide";
	}else{
		document.getElementById('name1').style.display="none"
			document.getElementById('showall').innerHTML = "Show all";
	}
}

function showall_all(){
	if(document.getElementById('name2').style.display=="none"){
		document.getElementById('name2').style.display="block";
		document.getElementById('showall-all').innerHTML = "HIDEN";
	}else{
		document.getElementById('name2').style.display="none"
			document.getElementById('showall-all').innerHTML = "Show all";
	}
}
</script>
